package com.mofeng.myshop.controller.admin;


import com.mofeng.myshop.domain.dto.AddressMapDto;
import com.mofeng.myshop.domain.dto.CommodityDto;
import com.mofeng.myshop.domain.dto.search.AddressMapSearchDto;
import com.mofeng.myshop.domain.po.AddressMap;
import com.mofeng.myshop.domain.vo.AddressMapVo;
import com.mofeng.myshop.domain.vo.CommodityVo;
import com.mofeng.myshop.service.IAddressService;
import com.mofeng.myshop.until.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 发货地址 前端控制器
 * </p>
 *
 * @author MoFeng
 * @since 2024-04-16
 */
@RestController
@RequestMapping("/admin/address")
@Tag(name = "地图接口", description = "地图")
@RequiredArgsConstructor
@PreAuthorize(value = "@permissionService.ROOT()")
public class AddressAdminController {

    private final IAddressService addressService;

    @Operation(summary = "添加地图信息")
    @PostMapping("")
    public R addAddress(@RequestBody AddressMapDto addressMapDto) {
        return addressService.saveAddress(addressMapDto);
    }


    @Operation(summary = "删除地图")
    @DeleteMapping("")
    public R delAddress(@RequestParam("id") List<String> ids) {
        return addressService.delAddress(ids);
    }


    @Operation(summary = "修改地图")
    @PutMapping("")
    public R updateAddress(@RequestBody AddressMapDto addressMapDto) {
        return addressService.saveAddress(addressMapDto);
    }

    @Operation(summary = "获取地图列表")
    @GetMapping("/list/{page}/{size}")
    public R getAddress(@PathVariable("page") Integer page,
                        @PathVariable("size") Integer size,
                        @RequestParam(value = "projectId", required = false) String projectId,
                        @RequestParam(value = "mapType", required = false) String mapType,
                        @RequestParam(value = "name", required = false) String name,
                        @RequestParam(value = "port", required = false) String port) {
        AddressMapSearchDto addressMapSearchDto = new AddressMapSearchDto();
        addressMapSearchDto.setPage(page);
        addressMapSearchDto.setSize(size);
        addressMapSearchDto.setProjectId(projectId);
        addressMapSearchDto.setMapType(mapType);
        addressMapSearchDto.setKeyword(name);
        addressMapSearchDto.setPort(port);
        return addressService.getAddressList(addressMapSearchDto);
    }
}
